using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace Test {
	class KontoCalc {
		static void MainX() {
			DAL dal=new DAL();

			//dal.NonQry("create table konint(id int identity,day date,bal decimal(10,2),int decimal(10,2))");
			dal.NonQry("truncate table konint");
			decimal sum=0;
			DateTime dat=DateTime.Now;
			for(int i=0;i<365*10;i++)
			{
				DateTime check=dat.AddDays(-i);
				object ob=dal.Scalar("select top 1 rem from konto(nolock)where day<='{0}'order by day desc,id desc",check.ToString("yyyy-MM-dd"));
				if(ob==null)
					break;
				decimal rem0=(decimal)ob;
				float prc=0;
				decimal rem=Math.Min(rem0,5000);
				if(rem>=3000)
					prc=3;
				else if(rem>=1000&&rem<3000)
					prc=2;
				else if(rem>=0&&rem<1000)
					prc=1;
				else
					continue;
				//throw new Exception();

				decimal dpro=rem*(decimal)prc/100/365;
				dpro=Math.Round(dpro,2);

				dal.NonQry("insert into konint(day,bal,int)values('{0}',{1},{2})",check.ToString("yyyy-MM-dd"),rem0,dpro);

				sum+=dpro;
			}


			Console.WriteLine(sum);

		}
	}
}
